/*
	Copyright (C) 2009 Salil Bhagurkar
	
	This file is part of ViSE
	
	ViSE is free software: you can redistribute it and/or modify
	it under the terms of the GNU Lesser General Public License as published by
	the Free Software Foundation, either version 3 of the License, or
	(at your option) any later version.
	
	ViSE is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU Lesser General Public License for more details.
	
	You should have received a copy of the GNU Lesser General Public License
	along with ViSE.  If not, see <http://www.gnu.org/licenses/>.
*/

#include <shared.h>

static int init_timer(struct node_fs *this);
static int deinit_timer(struct node_fs *this);

struct node_fs timer_fs = {
	.type = TYPE_FS_SERVER, 
	.name = "timed", 
	.class = NULL,
	.init = init_timer,
	.deinit = deinit_timer,
	NODE_FS_INIT_VARS,
	NODE_FS_OPS_INIT,
	NODE_FS_LIST_INIT};


static int timer_from_arch()
{
	struct node_fs *t;
	struct timer *tt;
	list_for(timer_fs.links, t) {
		tt = (struct timer *)t;
		tt->ctr--;
		if(tt->ctr == 0) {
			tt->ctr = 0xffffffff;
			t->init(t);
		}
	}
	return 0;
}

static int init_timer(struct node_fs *this)
{
	arch_configure_timer(timer_from_arch, 1000);
	return 0;
}

static int deinit_timer(struct node_fs *this)
{
	arch_remove_timer();
	return 0;
}

void init_timer_fs()
{
	//Register the timer fs dir
	fs_link("/", &timer_fs);
}
